package com.wj.opratorlog.cdc.debezium;/**
 * @author
 * @description
 * @create 2024-10-26-17:40
 **/

import com.alibaba.fastjson.JSON;

import java.util.Map;

/**
 * @author cnry
 * @date 2024/10/26
 * @description
 **/


public class DebeziumDataHande {
    public static Map<String, Object> getPayload(String value) {
        Map<String, Object> map = JSON.parseObject(value, Map.class);
        if(map.containsKey("payload")){
            return JSON.parseObject(JSON.toJSONString(map.get("payload")), Map.class);
        }
        return null;
    }

    public static Map<String, Object> getBefore(Map<String, Object> payload) {
        Map<String, Object> map = JSON.parseObject(payload.get("before").toString(), Map.class);
        return map;
    }

    public static Map<String, Object> getAfter(Map<String, Object> payload) {
        Map<String, Object> map = JSON.parseObject(payload.get("after").toString(), Map.class);
        return map;
    }

    public static Map<String, Object> getSource(Map<String, Object> payload) {
        Map<String, Object> map = JSON.parseObject(payload.get("source").toString(), Map.class);
        return map;
    }

    public static String getTableName(Map<String, Object> payload) {
        Map<String, Object> sourceMap = getSource(payload);
        String tableName =  sourceMap.get("table").toString();
        return tableName;
    }


}
